import React from 'react';
class StateAsync extends React.Component {
    state = {
        msg: 'hello react'
    };

    changeMsg = () => {
        this.setState(
            { msg: '你好 react' }, 
            () => {
                // 在该回调中可接收到此次state数据修改后的新数据
                console.log('新信息：',this.state.msg);
            }
        );
        
        console.log('接收不到新信息：', this.state.msg);
    }

    render() { 
        return <div>
            <h2>{ this.state.msg }</h2>
            <div onClick={ this.changeMsg }>点击改变msg</div>
        </div>;
    }
}
 
export default StateAsync;